package dictionary

import (
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "gorm.io/gorm"
    "iip/idgen"
    "iip/webserver"
    "libgo/network/gins/ginsession"
    "libgo/storage/db_config"
)

type Dictionary struct {
    cfg    *Config
    l      *zap.Logger
    logger *zap.SugaredLogger
    db     *gorm.DB

    idgen *idgen.IDGen
    dbcfg *db_config.DBConfig

    websrv *webserver.WebServer
    r      *gin.Engine
    ss     *ginsession.RediSessiontore
}

func New() *Dictionary {
    x := &Dictionary{}
    x.cfg = DefaultConfig()
    return x
}

func (s *Dictionary) WithLogger(l *zap.Logger) *Dictionary {
    s.l = l.With(zap.String("mod", "dictionary"))
    s.logger = s.l.Sugar()
    return s
}

func (s *Dictionary) WithConfig(cfg *Config) *Dictionary {
    s.cfg = cfg
    return s
}

func (s *Dictionary) WithDB(db *gorm.DB) *Dictionary {
    s.db = db
    return s
}

func (s *Dictionary) WithDBConfig(c *db_config.DBConfig) *Dictionary {
    s.dbcfg = c
    return s
}

func (s *Dictionary) WithIDGen(idgen *idgen.IDGen) *Dictionary {
    s.idgen = idgen
    return s
}

func (s *Dictionary) WithWebServer(srv *webserver.WebServer) *Dictionary {
    s.websrv = srv
    s.r = srv.GinEngine()
    s.ss = srv.SessionStore()
    return s
}

func (s *Dictionary) Start() {

    s._start_db()

    s._start_webserver()
}

func (s *Dictionary) _start_db() {












}

func (s *Dictionary) _start_webserver() {
    r := s.websrv.JWTProtectedRouterGroup("/api/v1")
    prefix := ""

    r.POST(prefix+"/business_role", s.BusinessRoleCreate)
    r.DELETE(prefix+"/business_role/:id", s.BusinessRoleDelete)
    r.GET(prefix+"/business_role", s.BusinessRolePagedList)
    r.GET(prefix+"/business_role/:id", s.BusinessRoleByID)
    r.PUT(prefix+"/business_role/:id", s.BusinessRoleUpdate)

    r.POST(prefix+"/location", s.LocationCreate)
    r.DELETE(prefix+"/location/:id", s.LocationDelete)
    r.GET(prefix+"/location", s.LocationPagedList)
    r.GET(prefix+"/location/:id", s.LocationByID)
    r.PUT(prefix+"/location/:id", s.LocationUpdate)

    r.POST(prefix+"/company", s.CompanyCreate)
    r.DELETE(prefix+"/company/:id", s.CompanyDelete)
    r.GET(prefix+"/company", s.CompanyPagedList)
    r.GET(prefix+"/company/:id", s.CompanyByID)
    r.PUT(prefix+"/company/:id", s.CompanyUpdate)

    r.POST(prefix+"/material", s.MaterialCreate)
    r.DELETE(prefix+"/material/:id", s.MaterialDelete)
    r.GET(prefix+"/material", s.MaterialPagedList)
    r.GET(prefix+"/material/:id", s.MaterialByID)
    r.PUT(prefix+"/material/:id", s.MaterialUpdate)

    r.POST(prefix+"/mine", s.MineCreate)
    r.DELETE(prefix+"/mine/:id", s.MineDelete)
    r.GET(prefix+"/mine", s.MinePagedList)
    r.GET(prefix+"/mine/:id", s.MineByID)
    r.PUT(prefix+"/mine/:id", s.MineUpdate)

    r.POST(prefix+"/factory", s.FactoryCreate)
    r.DELETE(prefix+"/factory/:id", s.FactoryDelete)
    r.GET(prefix+"/factory", s.FactoryPagedList)
    r.GET(prefix+"/factory/:id", s.FactoryByID)
    r.PUT(prefix+"/factory/:id", s.FactoryUpdate)

    r.POST(prefix+"/warehouse", s.WarehouseCreate)
    r.DELETE(prefix+"/warehouse/:id", s.WarehouseDelete)
    r.GET(prefix+"/warehouse", s.WarehousePagedList)
    r.GET(prefix+"/warehouse/:id", s.WarehouseByID)
    r.PUT(prefix+"/warehouse/:id", s.WarehouseUpdate)

    r.POST(prefix+"/driver", s.DriverCreate)
    r.DELETE(prefix+"/driver/:id", s.DriverDelete)
    r.GET(prefix+"/driver", s.DriverPagedList)
    r.GET(prefix+"/driver/:id", s.DriverByID)
    r.PUT(prefix+"/driver/:id", s.DriverUpdate)

    r.POST(prefix+"/truck", s.TruckCreate)
    r.DELETE(prefix+"/truck/:id", s.TruckDelete)
    r.GET(prefix+"/truck", s.TruckPagedList)
    r.GET(prefix+"/truck/:id", s.TruckByID)
    r.PUT(prefix+"/truck/:id", s.TruckUpdate)

    r.POST(prefix+"/weighbridge", s.WeighbridgeCreate)
    r.DELETE(prefix+"/weighbridge/:id", s.WeighbridgeDelete)
    r.GET(prefix+"/weighbridge", s.WeighbridgePagedList)
    r.GET(prefix+"/weighbridge/:id", s.WeighbridgeByID)
    r.PUT(prefix+"/weighbridge/:id", s.WeighbridgeUpdate)

    r.POST(prefix+"/external_project", s.ExternalProjectCreate)
    r.DELETE(prefix+"/external_project/:id", s.ExternalProjectDelete)
    r.GET(prefix+"/external_project", s.ExternalProjectPagedList)
    r.GET(prefix+"/external_project/:id", s.ExternalProjectByID)
    r.PUT(prefix+"/external_project/:id", s.ExternalProjectUpdate)

}
